/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package MainClass;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author 威
 */
public class ReadAndWriteUsers {
    
    public static Object readObjectFromFile()
    {
        Map temp = null;
        File file =new File("users.dat");
        FileInputStream in;
        try {
            in = new FileInputStream(file);
             System.out.println("0"); 
            ObjectInputStream objIn=new ObjectInputStream(in);
            System.out.println("1"); 
            temp= (Map) objIn.readObject();
            System.out.println("2"); 
            objIn.close();
            //System.out.println("read object success!");
        } catch (IOException e) {
            System.out.println(e);     
        } catch (ClassNotFoundException e) {
             System.out.println(e);
        }
        return temp;
    }
    
	public static void writeObjectToFile(Map obj)
    {
        File file =new File("users.dat");
        FileOutputStream out;
        try {
            out = new FileOutputStream(file);
            ObjectOutputStream objOut=new ObjectOutputStream(out);
            objOut.writeObject(obj);
            objOut.flush();
            objOut.close();
            //System.out.println("write object success!");
        } catch (IOException e) {
            System.out.println(e);
        }
    }
}
    
